package com.mywang.weitravel.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.mywang.weitravel.R;
import com.mywang.weitravel.model.RedLocateListBean;
import com.mywang.weitravel.modules.manbushanghai.WebViewActivity;
import com.mywang.weitravel.util.ImageLoader;

import java.util.List;

/**
 * Created by wangmingyun on 2019/12/11.
 */
public class NumberListAdapter extends RecyclerView.Adapter<NumberListAdapter.NumberHolder> {

    private Context context;

    private List<RedLocateListBean> mDatas;

    public NumberListAdapter(Context context, List<RedLocateListBean> mData) {
        this.context = context;
        this.mDatas = mData;
    }

    @NonNull
    @Override
    public NumberHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_number_list, null);
        return new NumberHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull NumberHolder holder, int position) {
        RedLocateListBean redLocateListBean = mDatas.get(position);
        ImageLoader.getInstance().displayImage(context, redLocateListBean.getFilepath(), holder.ivPic);
        holder.tvTitle.setText(redLocateListBean.getTitle());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, WebViewActivity.class);
                intent.putExtra(WebViewActivity.TITLE_NAME, redLocateListBean.getTitle());
                intent.putExtra(WebViewActivity.NAME_URL, redLocateListBean.getUrl());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    class NumberHolder extends RecyclerView.ViewHolder {

        ImageView ivPic;
        TextView tvTitle;

        public NumberHolder(@NonNull View itemView) {
            super(itemView);
            ivPic = itemView.findViewById(R.id.iv_pic);
            tvTitle = itemView.findViewById(R.id.tv_title);
        }
    }
}
